/*
		ServEngine framework library
		A library to fast develop JEE online applications
	
		Copyright 2008 José Ignacio de Córdoba Álvaro

		Licensed under the Apache License, Version 2.0 (the "License");
		you may not use this file except in compliance with the License.
		You may obtain a copy of the License at

				http://www.apache.org/licenses/LICENSE-2.0

		Unless required by applicable law or agreed to in writing, software
		distributed under the License is distributed on an "AS IS" BASIS,
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		See the License for the specific language governing permissions and
		limitations under the License.
	
		Jose Ignacio de Cordoba Alvaro
		http://ignacio.decordoba.com
*/

package com.servengine.user;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

@Entity
@Table (uniqueConstraints = {@UniqueConstraint(columnNames={"user_id","field_id"})})
public class ExtraUserdata implements java.io.Serializable
{
	Integer id;

	String value;

	ExtraUserdataField field;

	User user;

	public ExtraUserdata() {}

	public ExtraUserdata(ExtraUserdataField e, User user, String value)
	{
		this.user=user;
		this.value = value;
		field = e;
	}

	public boolean equals (Object item)
	{
		return ((ExtraUserdata)item).getId()==getId();
	}

	@Id @GeneratedValue
	public Integer getId()
	{
		return id;
	}

	@ManyToOne(fetch=FetchType.EAGER, optional=false)
	public ExtraUserdataField getField()
	{
		return field;
	}

	public String getValue()
	{
		return value;
	}

	public void setValue(String value)
	{
		this.value = value;
	}

	/**
	 * @Deprecated
	 */
	@Transient
	public String getFieldname()
	{
		return field.getName();
	}

	@Transient
	public String getFieldName()
	{
		return field.getName();
	}

	@Transient
	public boolean isRequired()
	{
		return field.isRequired();
	}

	@Transient
	public boolean isPublicField()
	{
		return field.isPublicField();
	}

	@ManyToOne(fetch=FetchType.EAGER, optional=false)
	public User getUser()
	{
		return user;
	}

	@Id @GeneratedValue
	public void setId(Integer id)
	{
		this.id = id;
	}

	public void setField(ExtraUserdataField field)
	{
		this.field = field;
	}

	public void setUser(User user)
	{
		this.user = user;
	}
}
